package com.gimi.cloud.jimi.dao.dao.prod;

import com.gimi.cloud.jimi.dao.common.SqlProvider;
import com.gimi.cloud.jimi.dao.dao.sys.BaseDao;
import com.gimi.cloud.jimi.dao.myMapper.MyMapper;
import com.gimi.cloud.jimi.dto.prod.ProdBrandDTO;
import com.gimi.cloud.jimi.dto.prod.ProdCatModelDTO;
import com.gimi.cloud.jimi.entity.prod.ProdBrandEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by lixj on 2017/12/18.
 */
@Mapper
public interface ProdBrandDao extends MyMapper<ProdBrandEntity>,BaseDao<ProdBrandEntity,ProdBrandDTO> {


    /**
     * 根据ID获取商品品类
     * @return
     * @param pdId
     */
    @Select("select t.* from ec_prod_brand t where t.pd_id=#{pdId}")
    List<ProdBrandDTO> getBrandListById(@Param(value = "pdId") Long pdId);
    /**
     * 获取商品品类列表
     * @return
     */
    @Select("SELECT * FROM ec_prod_brand WHERE 1=1 ")
    List<ProdBrandDTO> getBrandList();
    /**
     * 获取商品品类列表(分页)
     * @return
     */
    @SelectProvider(method = "sql",type = SqlProvider.class)
    List<ProdBrandDTO> queryPage(String sql);

    /**
     * 品牌后台页面展示，支持条件查询
     * @param prodBrandDTO
     * @return
     */
    List<ProdBrandDTO> queryPageList(ProdBrandDTO prodBrandDTO);

    /**
     * 转跳到编辑界面查询
     * @param prodBrandDTO
     * @return
     */
    ProdBrandDTO findProdBrandByPdId(ProdBrandDTO prodBrandDTO);
    
    /**
     * 根据品类ID查询对应的品牌
     * @param prodCatId
     * @return
     */
    List<ProdBrandDTO> getCatBrands(String prodCatId);
    /**
     * 删除品牌(逻辑删除)
     * @param prodBrandDTO
     */
    @Update("UPDATE ec_prod_brand SET type = #{isDelete} where pd_id=#{pdId}")
    void brandDelete(ProdBrandDTO prodBrandDTO);

    @Select("select t.* from ec_prod_brand t where t.prod_brand_name=#{prodBrandName}")
    List<ProdBrandDTO> getBrandListByName(String prodBrandName);

    @Select("SELECT * FROM ec_prod_brand WHERE pd_id = #{pdId} limit 1")
    ProdBrandEntity findByProdProdBrandId(@Param("pdId") Integer pdId);

    @Select("SELECT epb.* FROM ec_prod_category epc \n" +
            "LEFT JOIN ec_category_brand_rela ecbr ON epc.prod_cat_id=ecbr.prod_cat_id \n" +
            "LEFT JOIN ec_prod_brand epb on ecbr.prod_brand_id=epb.pd_id \n" +
            "where epc.prod_cat_id=#{prodCatId} limit 1")
    ProdBrandDTO selectProdBrandByProdCatId(ProdCatModelDTO dto);
}
